package dao.caminhoneiro;




import java.util.Properties;

import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import android.os.AsyncTask;
import android.widget.Toast;


import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;




import dao.caminhoneiro.PostRequest;


public class AsyncTask_Recuperar_Senha extends AsyncTask<Void, Void, String>{
	private ProgressDialog progress;
	private Context context;	
	private String cpf;
	private String retorno;
	private final String SERVER = "http://nome-produtor.rhcloud.com/caminhoneiro_recovery/";
	public AsyncTask_Recuperar_Senha(String cpf, Context context) {
		this.context 		= context;
		this.cpf = cpf;
	}
	
	@Override
	protected String doInBackground(Void... params) {
        PostRequest req = new PostRequest(SERVER);
        req.addParam("CPF", cpf);
		try{
			 retorno = req.doPostRequest().readLine();
			 return "OK";
		}catch(Exception e){
			return e.toString();
		}
		
	}
	@Override
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		progress.dismiss();
		if(result.equals("OK")){
			Toast.makeText(context, "Senha enviada para e-mail cadastrado.", Toast.LENGTH_SHORT).show();
		}else{
			Toast.makeText(context, result, Toast.LENGTH_LONG).show();
		}
	}
	
	@Override
	protected void onPreExecute() {
		// TODO Auto-generated method stub
		super.onPreExecute();
		progress = ProgressDialog.show(context, "Caminhoneiro", "Verificando conta, aguarde...");
	}
}
